import {
	ROLES_ACTION,
	SET_ROLES,
	GET_ROLES,
	GET_PERMI,
	SET_PERMI,
	PERMI_ACTION,
	STORAGE_ROLES,
	STORAGE_PERMI
} from '@/utils/Const';
import Storage from '@/utils/Storage';

export default {
	namespaced : true,
	state : {
		value : {
			roles : Storage.get(STORAGE_ROLES, 1) || [],
			permi : Storage.get(STORAGE_PERMI, 1) || []
		}
	},
	getters : {
		[GET_ROLES] : (state) => {
			return state.value.roles;
		},
		[GET_PERMI] : (state) => {
			return state.value.permi;
		}
	},
	mutations : {
		[SET_ROLES] (state, payload) {
			state.value.roles = payload;
			Storage.set(STORAGE_ROLES, payload, 1);
		},
		[SET_PERMI] (state, payload) {
			state.value.permi = payload;
			Storage.set(STORAGE_PERMI, payload, 1);
		}
	},
	actions : {
		[ROLES_ACTION] ({ commit }, payload) {
			commit(SET_ROLES, payload);
		},
		[PERMI_ACTION] ({ commit }, payload) {
			commit(SET_PERMI, payload);
		}
	}
};
